class_name CommonProgressBar
extends Node2D

var duration:float
var tween:Tween
var is_show:bool = false
signal on_start
signal on_end

func init_pb(duration:float,is_show:bool = true,on_start_action:Callable = Callable(),on_end_action:Callable = Callable()):
	self.duration = duration
	self.is_show = is_show
	if not on_start_action.is_null() and not on_start.is_connected(on_start_action):
		on_start.connect(on_start_action)
	if not on_end_action.is_null() and not on_end.is_connected(on_end_action):
		on_end.connect(on_end_action)
func start():
	visible = is_show
	tween = create_tween()
func end():
	if tween and tween.is_valid():
		tween.kill()
	visible = false
	
func _process(delta: float) -> void:
	if visible:
		if (scale.y > 0.001 and global_scale.y < -0.001) or (scale.y < -0.001 and global_scale.y > 0.001):
			apply_scale(Vector2(-1,1))
